package airthmetic.exercise.math;

public class _9_回文数 {
    public static boolean isPalindrome(int x) {
        if((x % 10  == 0 && x !=0) || x<0){
            return false;
        }

        int revertNum = 0;
        while (x > revertNum){
            revertNum = (revertNum * 10) + x % 10;
            x = x / 10;
        }

        return (x == revertNum) || (x == revertNum / 10);

    }

    public static boolean isPalindrome2(int x) {
      String revertNum = new StringBuilder(x + "").reverse().toString();
      return revertNum.equals(new StringBuilder(x+ "").toString());

    }

    public static void main(String[] args) {
        int x = 121;
        int x2 = 1221;
        int x3 = 12211;

//        System.out.println(isPalindrome(x));
//        System.out.println(isPalindrome(x2));
//        System.out.println(isPalindrome(x3));


        System.out.println(isPalindrome2(x));
        System.out.println(isPalindrome2(x2));
        System.out.println(isPalindrome2(x3));
    }
}
